package is.web.xdumper.client;

import is.web.htgen.form.*;
import is.bean.entity.department.Department;
import is.bean.entity.department.DepartmentBeanRemote;
import is.bean.entity.xdumper.session.XdumperSession;
import is.bean.entity.xdumper.session.XdumperSessionBeanRemoteHome;
import java.rmi.RemoteException;
import javax.ejb.FinderException;

/**
 * CRUD form generator
 *
 * @author aspr0
 */
public class XdumperClientSessionDeleteForm extends AbstractForm
{
    private final String rowsText =
            "<tr>"
            + "<td>Id</td>"
            + "<td>%s</td>"
            + "</tr>"
            + "<tr>"
            + "<td>Action</td>"
            + "<td>%s</td>"
            + "</tr>";
    private XdumperSessionBeanRemoteHome sessionHome;
    public final String ADVICE_CANVAS = "<div class=\"advice\">%s</div>";

    public void setSessionHome(XdumperSessionBeanRemoteHome sessionHome)
    {
        this.sessionHome = sessionHome;
    }

    public String genDelete(Integer id) throws RemoteException, FinderException
    {
        XdumperSession session = sessionHome.findByPrimaryKey(id).getData();

        String action = session.getAction();

        String rowsTextFilled = String.format(rowsText, id, action);
        String tableFilled = String.format(table, rowsTextFilled);

        String links = String.format(linksDiv, linkTable);
        links = String.format(links, id);
        String advice = String.format(ADVICE_CANVAS, "Confirm deleting session");

        return advice + String.format(form, tableFilled + inputSubmit) + links;
    }
}
